package com.fit.spring.boot.properties.autoscan.utils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.Closeable;
import java.io.Flushable;
import java.io.IOException;

/**
 * IO工具
 * @author hcl
 *
 */
public class IOUtil {
	private static Logger log = LoggerFactory.getLogger(IOUtil.class);
	/**
	 * 资源关闭方法(按顺序关闭)
	 * @param closeables
	 */
	public static void close(Closeable... closeables){
		if(closeables != null && closeables.length > 0){
			for(Closeable closeable : closeables){
				if(closeable != null){
					 try {
                    	try{
	                    	if(closeable instanceof Flushable){
	                    		((Flushable) closeable).flush();
	                    	}
                    	}finally{
                    		closeable.close();
                    	}
					} catch (IOException e) {
						log.error("关闭流异常",e);
					}
				}
			}
		}
	}
	
}
